
#include "keyboard.h"

void Keyboard_ReceiveEvent(const SDL_Event* event, CAMERA_MOVEMENT* movement) {
	switch(event->type)
    {
		case SDL_KEYDOWN:
            switch (event->key.keysym.sym)
            {
                case SDLK_LEFT:
                    *movement = (CAMERA_MOVEMENT)(*movement | CAMERA_MOVEMENT_LEFT);
                    break;
                case SDLK_RIGHT:
                    *movement = (CAMERA_MOVEMENT)(*movement | CAMERA_MOVEMENT_RIGHT);
                    break;
                case SDLK_UP:
                    *movement = (CAMERA_MOVEMENT)(*movement | CAMERA_MOVEMENT_UP);
                    break;
                case SDLK_DOWN:
                    *movement = (CAMERA_MOVEMENT)(*movement | CAMERA_MOVEMENT_DOWN);
                    break;
				case SDLK_1:
					Core_AddPeony();
					break;
                case SDLK_ESCAPE:
                    main_Quit();
                    break;
                case SDLK_c:
                    Display_ToggleCursor();
                    break;
                case SDLK_F11:
                    Display_ToggleFullScreen();
                    break;
				case SDLK_SPACE:
 					GraphicsCore_DrawMode(1);
					break;
            }
            /*Correction d'un bug de la SDL qui ne renvoie pas toujours le même keyCode en fonction du clavier ou de l'OS*/
            if (event->key.keysym.sym == fowardKey)
                *movement = (CAMERA_MOVEMENT)(*movement | CAMERA_MOVEMENT_FOWARD);
            if (event->key.keysym.sym == backKey)
                *movement = (CAMERA_MOVEMENT)(*movement | CAMERA_MOVEMENT_BACK);
            if (event->key.keysym.sym == leftKey)
                *movement = (CAMERA_MOVEMENT)(*movement | CAMERA_MOVEMENT_LEFT);
            if (event->key.keysym.sym == rightKey)
                *movement = (CAMERA_MOVEMENT)(*movement | CAMERA_MOVEMENT_RIGHT);
		break;
		case SDL_KEYUP:
            switch (event->key.keysym.sym)
            {
                case SDLK_LEFT:
                    *movement = (CAMERA_MOVEMENT)(*movement & (~CAMERA_MOVEMENT_LEFT));
                    break;
                case SDLK_RIGHT:
                    *movement = (CAMERA_MOVEMENT)(*movement & (~CAMERA_MOVEMENT_RIGHT));
                    break;
                case SDLK_UP:
                    *movement = (CAMERA_MOVEMENT)(*movement & (~CAMERA_MOVEMENT_UP));
                    break;
                case SDLK_DOWN:
                    *movement = (CAMERA_MOVEMENT)(*movement & (~CAMERA_MOVEMENT_DOWN));
                    break;
				case SDLK_SPACE:
 					GraphicsCore_DrawMode(2);
					break;
            }
            if (event->key.keysym.sym == fowardKey)
                *movement = (CAMERA_MOVEMENT)(*movement & (~CAMERA_MOVEMENT_FOWARD));
            if (event->key.keysym.sym == backKey)
                *movement = (CAMERA_MOVEMENT)(*movement & (~CAMERA_MOVEMENT_BACK));
            if (event->key.keysym.sym == leftKey)
                *movement = (CAMERA_MOVEMENT)(*movement & (~CAMERA_MOVEMENT_LEFT));
            if (event->key.keysym.sym == rightKey)
                *movement = (CAMERA_MOVEMENT)(*movement & (~CAMERA_MOVEMENT_RIGHT));
		break;
    }
}

